package com.lxmes.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.lxmes.business.domain.NcMeasuringInstrumentCalibration;
import com.lxmes.business.service.INcMeasuringInstrumentCalibrationService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 量检具校验记录Controller
 * 
 * @author lx
 * @date 2023-06-01
 */
@Api(tags = "量检具校验记录")    
@RestController
@RequestMapping("/business/NcMeasuringInstrumentCalibration")
public class NcMeasuringInstrumentCalibrationController extends BaseController
{
    @Autowired
    private INcMeasuringInstrumentCalibrationService ncMeasuringInstrumentCalibrationService;

    /**
     * 查询量检具校验记录列表
     */
    @ApiOperation("查询量检具校验记录列表")
    @PreAuthorize("@ss.hasPermi('business:NcMeasuringInstrumentCalibration:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcMeasuringInstrumentCalibration ncMeasuringInstrumentCalibration)
    {
        startPage();
        List<NcMeasuringInstrumentCalibration> list = ncMeasuringInstrumentCalibrationService.selectNcMeasuringInstrumentCalibrationList(ncMeasuringInstrumentCalibration);
        return getDataTable(list);
    }

    /**
     * 导出量检具校验记录列表
     */
    @ApiOperation("导出量检具校验记录列表")
    @PreAuthorize("@ss.hasPermi('business:NcMeasuringInstrumentCalibration:export')")
    @Log(title = "量检具校验记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcMeasuringInstrumentCalibration ncMeasuringInstrumentCalibration)
    {
        List<NcMeasuringInstrumentCalibration> list = ncMeasuringInstrumentCalibrationService.selectNcMeasuringInstrumentCalibrationList(ncMeasuringInstrumentCalibration);
        ExcelUtil<NcMeasuringInstrumentCalibration> util = new ExcelUtil<NcMeasuringInstrumentCalibration>(NcMeasuringInstrumentCalibration.class);
        util.exportExcel(response, list, "量检具校验记录数据");
    }

    /**
     * 获取量检具校验记录详细信息
     */
    @ApiOperation("获取量检具校验记录详细信息")
    @PreAuthorize("@ss.hasPermi('business:NcMeasuringInstrumentCalibration:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncMeasuringInstrumentCalibrationService.selectNcMeasuringInstrumentCalibrationById(id));
    }

    /**
     * 新增量检具校验记录
     */
    @ApiOperation("新增量检具校验记录")
    @PreAuthorize("@ss.hasPermi('business:NcMeasuringInstrumentCalibration:add')")
    @Log(title = "量检具校验记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcMeasuringInstrumentCalibration ncMeasuringInstrumentCalibration)
    {
        return toAjax(ncMeasuringInstrumentCalibrationService.insertNcMeasuringInstrumentCalibration(ncMeasuringInstrumentCalibration));
    }

    /**
     * 修改量检具校验记录
     */
    @ApiOperation("修改量检具校验记录")
    @PreAuthorize("@ss.hasPermi('business:NcMeasuringInstrumentCalibration:edit')")
    @Log(title = "量检具校验记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcMeasuringInstrumentCalibration ncMeasuringInstrumentCalibration)
    {
        return toAjax(ncMeasuringInstrumentCalibrationService.updateNcMeasuringInstrumentCalibration(ncMeasuringInstrumentCalibration));
    }

    /**
     * 删除量检具校验记录
     */
    @ApiOperation("删除量检具校验记录")
    @PreAuthorize("@ss.hasPermi('business:NcMeasuringInstrumentCalibration:remove')")
    @Log(title = "量检具校验记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncMeasuringInstrumentCalibrationService.deleteNcMeasuringInstrumentCalibrationByIds(ids));
    }
    /**
     * 导入量检具校验记录
     */
    @Log(title = "量检具校验记录", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<NcMeasuringInstrumentCalibration> util = new ExcelUtil<>(NcMeasuringInstrumentCalibration.class);
        List<NcMeasuringInstrumentCalibration> ncMeasuringInstrumentCalibrationList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ncMeasuringInstrumentCalibrationService.imporIteminfo(ncMeasuringInstrumentCalibrationList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<NcMeasuringInstrumentCalibration> util = new ExcelUtil<>(NcMeasuringInstrumentCalibration.class);
        util.importTemplateExcel(response,"量检具校验记录");
    }
}
